package com.sxt.practiceapplication.utils.permission;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Build;

public class PermissionManager {

    public static final String KEY_PERMISSIONS = "permissions";

    private static final int RC_REQUEST_PERMISSION = 100;

    private final PermissionCallback callback;

    private final Context context;

    private String[] permissions;

    public PermissionManager(Context context, String[] permissions, PermissionCallback callback) {
        this.callback = callback;
        this.context = context;
        this.permissions = permissions;
    }

    @SuppressLint("ObsoleteSdkInt")
    public void requestPermissions() {
        if(permissions.length == 0) {
            return;
        }
        // 当api大于23时，才进行权限申请
        if (Build.VERSION.SDK_INT >= 23 && context instanceof Activity) {
            Activity activity = (Activity)context;
            activity.requestPermissions(permissions, RC_REQUEST_PERMISSION);
        }
    }

}
